#!/bin/sh

a=$(ip address | grep ^[0-9] | awk -F: '{print $2}' | sed "s/ //g" | grep '^[e]' | grep -v "@" | grep -v "\.")
b=$(echo "$a" | wc -l)
rm -f /tmp/state/ethinfo

for i in $(seq 1 $b)
do
	c=$(echo "$a" | sed -n ${i}p)
	d=$(ethtool $c)
	e=$(echo "$d" | grep "Link detected" | awk -F: '{printf $2}' | sed 's/^[ \t]*//g')
	f=$(echo "$d" | grep "Speed" | awk -F: '{printf $2}' | sed 's/^[ \t]*//g' | tr -d "Unknown!")
	[ -z "$f" ] && f="-"
	g=$(echo "$d" | grep "Duplex" | awk -F: '{printf $2}' | sed 's/^[ \t]*//g')
	[ "$g" != "Full" -a "$g" != "Half" ] && g="-"
	echo "$c $e $f $g" >> /tmp/state/ethinfo
done
